﻿// BinaryOperationTable.cs （无改动）

public sealed class BinaryOperationTable<TIn, TOut>
{
    public delegate TOut BinaryOperation(TIn input1, TIn input2);

    public sealed record Result(TIn Input1, TIn Input2, TOut Output, string Sign) : IFormattable
    {
        public override string ToString()
        {
            return ToString("{0} {3} {1} = {2}");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="format">
        /// <c>{0}</c>：<see cref="Input1"/>
        /// <c>{1}</c>：<see cref="Input2"/>
        /// <c>{2}</c>：<see cref="Output"/>
        /// <c>{3}</c>：<see cref="Sign"/>
        /// </param>
        /// <param name="formatProvider"></param>
        /// <returns></returns>
        public string ToString(string? format, IFormatProvider? formatProvider = null)
        {
            return string.Format(format ?? string.Empty,
                Input1, Input2, Output, Sign);
        }
    }

    public BinaryOperation Operation { get; }
    public string Sign { get; }
    public BinaryOperationTable(BinaryOperation operation, string sign)
    {
        this.Operation = operation;
        this.Sign = sign;
    }

    public Result this[TIn input1, TIn input2]
    {
        get
        {
            return new(input1, input2, Operation(input1, input2), Sign);
        }
    }
}